<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\AppBaseController;
use App\Models\ParkChannels;
use App\Models\Report;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Models\ParkInfo;
use App\Http\Controllers\Controller;
use Excel;

class ReportController extends AppBaseController
{
    public function dayReport(Request $request)
    {
//        $this->validate($request, [
//            'type' => 'required',
//            'report_date' => 'required'
//        ]);

        $res = Report::where(['report_date' => $request->report_date, 'type' => $request->type])
            ->orderBy('report_date','desc')
            ->first();
        $res->download_number+=1;
        $res->save();
        $this->{$request->get('type')}($res->value);

        return 1;
    }

    /**
     * 收费员日报
     *
     * @param $value
     */
    public function charger_count_day_report($value)
    {
        $cellData = [
            ['车场', '收费员', '现金收入', '小计', '手动免费', '小计']
        ];

        Excel::create('收费员日报', function ($excel) use ($cellData, $value) {
            $excel->sheet('sheet1', function ($sheet) use ($cellData, $value) {

                $date = date("Y年m月d号",strtotime($_GET['report_date']));
                $sheet->setCellValue('A1', '收费员日报表('.$date.')     ');
                $sheet->mergeCells('A1:F1','center');

                $sheet->setCellValue('A2' , $cellData[0][0])->cells('A2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('B2' , $cellData[0][1])->cells('B2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('C2' , $cellData[0][2])->cells('C2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('D2' , $cellData[0][3])->cells('D2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('E2', $cellData[0][4])->cells('E2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('F2', $cellData[0][5])->cells('F2', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setWidth(array('A' => 35, 'B' => 35, 'C' => 35, 'D' => 35, 'E' => 35, 'F' => 35));
                $i = $z= 3;
                $data = $value['data'];
                $money = 0;
                $freeTotal = 0;
                foreach ($data as $v) {
                    $num = count($v['chargeList']);
                    if ($num == 0) continue;
                    $str = 'A' . $i . ':A' . ($i + $num - 1);
                    $sheet->mergeCells($str,'center');
                    $sheet->setCellValue('A' . $i, $v['parking_name'])->cells('A' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    //收费员循环
                    $z = $i;
                    foreach ($v['chargeList'] as $charger) {
                        $sheet->setCellValue('B' . $z, $charger['charger'])->cells('B' . $z, function ($cell){
                            $cell->setAlignment("center");
                        });
                        $sheet->setCellValue('C' . $z, $charger['charger_money'])->cells('C' . $z, function ($cell){
                            $cell->setAlignment("center");
                        });
                        $sheet->setCellValue('E' . $z, $charger['hand_free'])->cells('E' . $z, function ($cell){
                            $cell->setAlignment("center");
                        });
                        $z++;
                    }

                    $str = 'D' . $i . ':D' . ($i + $num - 1);
                    $sheet->mergeCells($str);
                    $sheet->setCellValue('D' . $i, $v['little_total'])->cells('D' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });

                    $str = 'F' . $i . ':F' . ($i + $num - 1);
                    $sheet->mergeCells($str);
                    $sheet->setCellValue('F' . $i, $v['little_total_free'])->cells('F' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });;

                    $money += $v['little_total'];
                    $freeTotal += $v['little_total_free'];

                    $i = ($i + $num);

                }
                $str = 'A' . $z . ':B' . $z;
                $sheet->mergeCells($str);
                $sheet->setCellValue('A' . $z, '合计')->cells('A' . $z, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('C' . $z, $money)->cells('C' . $z, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('D' . $z, $money)->cells('D' . $z, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('E' . $z, $freeTotal)->cells('E' . $z, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('F' . $z, $freeTotal)->cells('F' . $z, function ($cell){
                    $cell->setAlignment("center");
                });

            });
        })->export('xls');
    }

    public function overnight_count($value)
    {
        $cellData = [
            ['日期']
        ];
        //拼接车场
        foreach (array_values($value)[0]['list'] as $v) {
            if (isset($v['parking_name'])) {
                $cellData[0][] = $v['parking_name'];
            }
        }

        $cellData[0][] = '合计';

        foreach ($value as $date => $item) {
            $row = [
                $date
            ];

            foreach ($item['list'] as $k => $park) {
                $row[] = $park['inner_car'];
            }
            
            $row[] = $item['total'];
            $cellData[] = $row;
        }
        Excel::create('过夜车月报', function ($excel) use ($cellData) {
            $excel->sheet('sheet1', function ($sheet) use ($cellData) {
                $hlength = count($cellData[0])-1;
                $endWord = strtoupper(getnumhalp($hlength));

                $date = date("Y年m月", strtotime($_GET['report_date']));
                $sheet->setCellValue('A1', $date.'过夜车报表')->cells('A1', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->mergeCells("A1:". $endWord ."1",'center');
                $i=2;
                foreach ($cellData as $cell) {
                    $sheet->setCellValue('A'.$i, $cell[0])->cells('A'.$i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('B'.$i, $cell[1])->cells('B'.$i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('C'.$i, $cell[2])->cells('C'.$i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('D'.$i, $cell[3])->cells('D'.$i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('E'.$i, $cell[4])->cells('E'.$i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('F'.$i, $cell[5])->cells('F'.$i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('G'.$i, $cell[6])->cells('G'.$i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('H'.$i, $cell[7])->cells('H'.$i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('I'.$i, $cell[8])->cells('I'.$i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('J'.$i, isset($cell[9])?$cell[9]:'')->cells('J'.$i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('K'.$i, isset($cell[10])?$cell[10]:'')->cells('K'.$i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $i++;
                }
                $rowName = strtoupper(getnumhalp(count($cellData[0])));
            });
        })->export('xls');
    }

    // public function overnight_count($value)
    // {
    //     $cellData = [
    //         ['日期']
    //     ];
    //     //拼接车场
    //     $parks = $value[0];
    //     foreach ($parks as $v) {
    //         if (isset($v['parking_name'])) {
    //             $cellData[0][] = $v['parking_name'];
    //         }
    //     }

    //     $cellData[0][] = '合计';

    //     foreach ($value as $dayValue) {
    //         $date = $dayValue['date'];

    //         $row = [
    //             $date
    //         ];

    //         foreach ($dayValue as $k => $parkDate) {

    //             if (is_numeric($k)) {
    //                 $row[] = $parkDate['inner_car'];
    //             }
    //         }
    //         $row[] = $dayValue['total'];
    //         $cellData[] = $row;
    //     }
    //     Excel::create('过夜车月报', function ($excel) use ($cellData, $value) {
    //         $excel->sheet('sheet1', function ($sheet) use ($cellData, $value) {
    //             $hlength = count($cellData[0])-1;
    //             $endWord = strtoupper(getnumhalp($hlength));
    //             $date = date("Y年m月",strtotime($_GET['report_date']));
    //             $sheet->setCellValue('A1', $date.'过夜车报表')->cells('A1', function ($cell){
    //                 $cell->setAlignment("center");
    //             });
    //             $sheet->mergeCells("A1:".$endWord."1",'center');
    //             $i=2;
    //             foreach ($cellData as $cell) {
    //                 $sheet->setCellValue('A'.$i, $cell[0])->cells('A'.$i, function ($cell){
    //                     $cell->setAlignment("center");
    //                 });
    //                 $sheet->setCellValue('B'.$i, $cell[1])->cells('B'.$i, function ($cell){
    //                     $cell->setAlignment("center");
    //                 });
    //                 $sheet->setCellValue('C'.$i, $cell[2])->cells('C'.$i, function ($cell){
    //                     $cell->setAlignment("center");
    //                 });
    //                 $sheet->setCellValue('D'.$i, $cell[3])->cells('D'.$i, function ($cell){
    //                     $cell->setAlignment("center");
    //                 });
    //                 $sheet->setCellValue('E'.$i, $cell[4])->cells('E'.$i, function ($cell){
    //                     $cell->setAlignment("center");
    //                 });
    //                 $sheet->setCellValue('F'.$i, $cell[5])->cells('F'.$i, function ($cell){
    //                     $cell->setAlignment("center");
    //                 });
    //                 $sheet->setCellValue('G'.$i, $cell[6])->cells('G'.$i, function ($cell){
    //                     $cell->setAlignment("center");
    //                 });
    //                 $sheet->setCellValue('H'.$i, $cell[7])->cells('H'.$i, function ($cell){
    //                     $cell->setAlignment("center");
    //                 });
    //                 $sheet->setCellValue('I'.$i, $cell[8])->cells('I'.$i, function ($cell){
    //                     $cell->setAlignment("center");
    //                 });
    //                 $sheet->setCellValue('J'.$i, $cell[9])->cells('J'.$i, function ($cell){
    //                     $cell->setAlignment("center");
    //                 });
    //                 $sheet->setCellValue('K'.$i, $cell[10])->cells('K'.$i, function ($cell){
    //                     $cell->setAlignment("center");
    //                 });
    //                 $i++;
    //             }
    //             $rowName = strtoupper(getnumhalp(count($cellData[0])));
    //         });
    //     })->export('xls');
    // }

    public function flow_count_day_report($value)
    {
        // $parks_code = config('custom.report_parks');
        $parks_code = config('custom.report_flow_parks');
        // $parks = ParkInfo::whereIn('park_code', config('custom.report_parks'))
        $parks = ParkInfo::whereIn('park_code', $parks_code)
            ->select(['park_code', 'parking_name'])
            ->orderBy('sort_by', 'desc')
            ->get();
        $sort_num = 0;
        foreach ($parks_code as $val) {
            foreach ($parks as &$p) {
                if($p->park_code == $val){
                    $p->sort_num = $sort_num;
                    $sort_num++;
                }
            }
        }
        $parks = $parks->sortBy('sort_num');
        $cellData = [];
        $day_type = count(explode("-",$_GET['report_date']));
        $title = $day_type==2? "月" : "日";
        Excel::create('流量'.$title.'报表', function ($excel) use ($cellData, $value, $parks,$day_type) {
            $excel->sheet('sheet1', function ($sheet) use ($cellData, $value, $parks,$day_type) {
                $keyed = $parks->pluck('parking_name', 'park_code')->toArray();
                $total = [
                    '0_15_charge' => 0,
                    '0_15_free' => 0,
                    '15_30_charge' => 0,
                    '15_30_free' => 0,
                    'charge' => 0,
                    'free' => 0,
                    'greater_1440_charge' => 0,
                    'greater_1440_free' => 0,
                    'total' => 0
                ];
                for ($i = 30; $i < 1440; $i += 30) {
                    $end = $i + 30;
                    $total["{$i}_{$end}_free"] = 0;
                    $total["{$i}_{$end}_charge"] = 0;
                }
                $hlength = count($keyed)*2+2;
                $endWord = strtoupper(getnumhalp($hlength));
                $date = $day_type==2? date("Y年m月",strtotime($_GET['report_date'])):date("Y年m月d号",strtotime($_GET['report_date']));
                $sheet->setCellValue('A1', '商业管理部停车场车流量统计明细表（'.$date.'）     ');
                $sheet->mergeCells("A1:".$endWord."1",'center');

                $sheet->mergeCells('A2:A3','center');
                $sheet->setCellValue('A2', '时段')->cells('A2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('A4', '0-15分钟')->cells('A4', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('A5', '15-30分钟')->cells('A5', function ($cell){
                    $cell->setAlignment("center");
                });
                //第一列
                $a = 6;
                for ($i = 30; $i < 1440; $i += 30) {
                    $sheet->setCellValue('A' . $a, ($i / 60) . '-' . (($i + 30) / 60) . '小时'.'     ')->cells('A' . $a, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $a++;
                }
                $sheet->setCellValue('A' . $a, '24小时以上')->cells('A' . $a, function ($cell){
                    $cell->setAlignment("center");
                });
                $a++;
                $sheet->setCellValue('A' . $a, '合计')->cells('A' . $a, function ($cell){
                    $cell->setAlignment("center");
                });
                $a++;
                $sheet->setCellValue('A' . $a, '总计')->cells('A' . $a, function ($cell){
                    $cell->setAlignment("center");
                });

                $start = ord('B');
                foreach ($parks as $park) {
                    $sheet->setCellValue($this->safeChr($start) . '2', $park->parking_name)->cells($this->safeChr($start) . '2', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue($this->safeChr($start) . '3', '收费车              ')->cells($this->safeChr($start) . '3', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue($this->safeChr($start + 1) . '3', '免费车              ')->cells($this->safeChr($start + 1) . '3', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->mergeCells($this->safeChr($start) . '2:' . $this->safeChr($start + 1) . '2','center');

                    //设置单元格
                    $sheet->setCellValue($this->safeChr($start) . '4', $value["time_{$park->park_code}_0_15_charge"]??0)->cells($this->safeChr($start) . '4', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['0_15_charge'] += $value["time_{$park->park_code}_0_15_charge"]??0;

                    $sheet->setCellValue($this->safeChr($start + 1) . '4', $value["time_{$park->park_code}_0_15_free"]??0)->cells($this->safeChr($start + 1) . '4', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['0_15_free'] += $value["time_{$park->park_code}_0_15_free"]??0;

                    $sheet->setCellValue($this->safeChr($start) . '5', $value["time_{$park->park_code}_15_30_charge"]??0)->cells($this->safeChr($start) . '5', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['15_30_charge'] += $value["time_{$park->park_code}_15_30_charge"]??0;

                    $sheet->setCellValue($this->safeChr($start + 1) . '5', $value["time_{$park->park_code}_15_30_free"]??0)->cells($this->safeChr($start + 1) . '5', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['15_30_free'] += $value["time_{$park->park_code}_15_30_free"]??0;
                    $index = 6;
                    for ($i = 30; $i < 1440; $i += 30) {
                        $end = $i + 30;
                        $sheet->setCellValue($this->safeChr($start) . $index, $value["time_{$park->park_code}_{$i}_{$end}_charge"]??0)->cells($this->safeChr($start) . $index, function ($cell){
                            $cell->setAlignment("center");
                        });
                        $sheet->setCellValue($this->safeChr($start + 1) . $index, $value["time_{$park->park_code}_{$i}_{$end}_free"]??0)->cells($this->safeChr($start + 1) . $index, function ($cell){
                            $cell->setAlignment("center");
                        });
                        $total["{$i}_{$end}_free"] += $value["time_{$park->park_code}_{$i}_{$end}_free"]??0;
                        $total["{$i}_{$end}_charge"] += $value["time_{$park->park_code}_{$i}_{$end}_charge"]??0;
                        $index++;
                    }
                    $sheet->setCellValue($this->safeChr($start) . $index, $value["time_{$park->park_code}_greater_1440_charge"]??0)->cells($this->safeChr($start) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['greater_1440_charge'] += $value["time_{$park->park_code}_greater_1440_charge"]??0;

                    $sheet->setCellValue($this->safeChr($start + 1) . $index, $value["time_{$park->park_code}_greater_1440_free"]??0)->cells($this->safeChr($start + 1) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['greater_1440_free'] += $value["time_{$park->park_code}_greater_1440_free"]??0;

                    $index++;

                    $sheet->setCellValue($this->safeChr($start) . $index, $value["time_{$park->park_code}_charge"]??0)->cells($this->safeChr($start) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['charge'] += $value["time_{$park->park_code}_charge"]??0;

                    $sheet->setCellValue($this->safeChr($start + 1) . $index, $value["time_{$park->park_code}_free"]??0)->cells($this->safeChr($start + 1) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['free'] += $value["time_{$park->park_code}_free"]??0;
                    $index++;

                    $sheet->setCellValue($this->safeChr($start) . $index, $value["time_{$park->park_code}_total"]??0)->cells($this->safeChr($start) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['total'] += $value["time_{$park->park_code}_total"]??0;

                    $sheet->mergeCells($this->safeChr($start) . $index . ':' . $this->safeChr($start + 1) . $index,'center');

                    $start += 2;
                }

                $sheet->setCellValue($this->safeChr($start) . '2', '小计')->cells($this->safeChr($start) . '2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->mergeCells($this->safeChr($start) . '2:' . $this->safeChr($start + 1) . '2','center');
                $sheet->setCellValue($this->safeChr($start) . '3', '收费车')->cells($this->safeChr($start) . '3', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue($this->safeChr($start + 1) . '3', '免费车')->cells($this->safeChr($start + 1) . '3', function ($cell){
                    $cell->setAlignment("center");
                });
                //设置单元格
                $sheet->setCellValue($this->safeChr($start) . '4', $total["0_15_charge"])->cells($this->safeChr($start) . '4', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue($this->safeChr($start + 1) . '4', $total["0_15_free"])->cells($this->safeChr($start + 1) . '4', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue($this->safeChr($start) . '5', $total["15_30_charge"])->cells($this->safeChr($start) . '5', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue($this->safeChr($start + 1) . '5', $total["15_30_free"])->cells($this->safeChr($start + 1) . '5', function ($cell){
                    $cell->setAlignment("center");
                });


                $index = 6;
                for ($i = 30; $i < 1440; $i += 30) {
                    $end = $i + 30;
                    $sheet->setCellValue($this->safeChr($start) . $index, $total["{$i}_{$end}_charge"])->cells($this->safeChr($start) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    ;
                    $sheet->setCellValue($this->safeChr($start + 1) . $index, $total["{$i}_{$end}_free"])->cells($this->safeChr($start + 1) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    ;
                    $index++;
                }
                $sheet->setCellValue($this->safeChr($start) . $index, $total["greater_1440_charge"])->cells($this->safeChr($start) . $index, function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue($this->safeChr($start + 1) . $index, $total["greater_1440_free"])->cells($this->safeChr($start + 1) . $index, function ($cell){
                    $cell->setAlignment("center");
                });

                $index++;
                $sheet->setCellValue($this->safeChr($start) . $index, $total["charge"])->cells($this->safeChr($start) . $index, function ($cell){
                    $cell->setAlignment("center");
                });


                $sheet->setCellValue($this->safeChr($start + 1) . $index, $total['free'])->cells($this->safeChr($start + 1) . $index, function ($cell){
                    $cell->setAlignment("center");
                });


                $index++;

                $sheet->setCellValue($this->safeChr($start) . $index, $total["total"])->cells($this->safeChr($start) . $index, function ($cell){
                    $cell->setAlignment("center");
                });


                $sheet->mergeCells($this->safeChr($start) . $index . ':' . $this->safeChr($start + 1) . $index,'center');

            });
        })->export('xls');
    }

    public function flow_count_month_report($value)
    {
        $this->flow_count_day_report($value);
    }

    public function flow_count_year_report($value)
    {
        $this->flow_count_day_report($value);
    }

    public function charge_count_day_report($value)
    {
        $parks = ParkInfo::whereIn('park_code', config('custom.report_parks'))
            ->select(['park_code', 'parking_name'])
            ->orderBy('sort_by', 'desc')
            ->get();
        $parks_code = config('custom.report_parks');
        $sort_num = 0;
        foreach ($parks_code as $val) {
            foreach ($parks as &$p) {
                if($p->park_code == $val){
                    $p->sort_num = $sort_num;
                    $sort_num++;
                }
            }
        }
        $parks = $parks->sortBy('sort_num');
        $cellData = [];
        $day_type = count(explode("-",$_GET['report_date']));
        $title = $day_type==2? "月" : "日";
        Excel::create('收入表', function ($excel) use ($cellData, $value, $parks,$day_type) {
            $excel->sheet('sheet1', function ($sheet) use ($cellData, $value, $parks,$day_type) {
                $keyed = $parks->pluck('parking_name', 'park_code')->toArray();
                $total = [
                    '0_15_big' => 0,
                    '0_15_little' => 0,
                    '15_30_big' => 0,
                    '15_30_little' => 0,
                    'big' => 0,
                    'little' => 0,
                    'greater_1440_big' => 0,
                    'greater_1440_little' => 0,
                    'total' => 0
                ];
                for ($i = 30; $i < 1440; $i += 30) {
                    $end = $i + 30;
                    $total["{$i}_{$end}_little"] = 0;
                    $total["{$i}_{$end}_big"] = 0;
                }
                $hlength = count($keyed)*2+2;
                $endWord = strtoupper(getnumhalp($hlength));
                $date = $day_type==2? date("Y年m月",strtotime($_GET['report_date'])):date("Y年m月d号",strtotime($_GET['report_date']));
                $sheet->setCellValue('A1', '商业管理部停车场收入分析表('.$date.')     ')->cells('A1', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->mergeCells("A1:".$endWord."1",'center');

                $sheet->mergeCells('A2:A3');
                $sheet->setCellValue('A2', '时段')->cells('A2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('A4', '0-15分钟')->cells('A4', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('A5', '15-30分钟')->cells('A5', function ($cell){
                    $cell->setAlignment("center");
                });
                //第一列
                $a = 6;
                for ($i = 30; $i < 1440; $i += 30) {
                    $sheet->setCellValue('A' . $a, ($i / 60) . '-' . (($i + 30) / 60) . '小时')->cells('A' . $a, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $a++;
                }
                $sheet->setCellValue('A' . $a, '24小时以上')->cells('A' . $a, function ($cell){
                    $cell->setAlignment("center");
                });
                $a++;
                $sheet->setCellValue('A' . $a, '合计')->cells('A' . $a, function ($cell){
                    $cell->setAlignment("center");
                });
                $a++;
                $sheet->setCellValue('A' . $a, '总计')->cells('A' . $a, function ($cell){
                    $cell->setAlignment("center");
                });

                $start = ord('B');

                foreach ($parks as $park) {
                    $sheet->setCellValue($this->safeChr($start) . '2', $park->parking_name)->cells($this->safeChr($start) . '2', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue($this->safeChr($start) . '3', '大车')->cells($this->safeChr($start) . '3', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue($this->safeChr($start + 1) . '3', '小车')->cells($this->safeChr($start + 1) . '3', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->mergeCells($this->safeChr($start) . '2:' . $this->safeChr($start + 1) . '2','center');

                    //设置单元格
                    $sheet->setCellValue($this->safeChr($start) . '4', $value["time_{$park->park_code}_0_15_big"]??0)->cells($this->safeChr($start) . '4', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['0_15_big'] += $value["time_{$park->park_code}_0_15_big"]??0;

                    $sheet->setCellValue($this->safeChr($start + 1) . '4', $value["time_{$park->park_code}_0_15_little"]??0)->cells($this->safeChr($start + 1) . '4', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['0_15_little'] += $value["time_{$park->park_code}_0_15_little"]??0;

                    $sheet->setCellValue($this->safeChr($start) . '5', $value["time_{$park->park_code}_15_30_big"]??0)->cells($this->safeChr($start ) . '5', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['15_30_big'] += $value["time_{$park->park_code}_15_30_big"]??0;

                    $sheet->setCellValue($this->safeChr($start + 1) . '5', $value["time_{$park->park_code}_15_30_little"]??0)->cells($this->safeChr($start + 1) . '5', function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['15_30_little'] += $value["time_{$park->park_code}_15_30_little"]??0;
                    $index = 6;
                    for ($i = 30; $i < 1440; $i += 30) {
                        $end = $i + 30;
                        $sheet->setCellValue($this->safeChr($start) . $index, $value["time_{$park->park_code}_{$i}_{$end}_big"]??0)->cells($this->safeChr($start) . $index, function ($cell){
                            $cell->setAlignment("center");
                        });
                        $sheet->setCellValue($this->safeChr($start + 1) . $index, $value["time_{$park->park_code}_{$i}_{$end}_little"]??0)->cells($this->safeChr($start + 1) . $index, function ($cell){
                            $cell->setAlignment("center");
                        });
                        $total["{$i}_{$end}_little"] += $value["time_{$park->park_code}_{$i}_{$end}_little"]??0;
                        $total["{$i}_{$end}_big"] += $value["time_{$park->park_code}_{$i}_{$end}_big"]??0;
                        $index++;
                    }
                    $sheet->setCellValue($this->safeChr($start) . $index, $value["time_{$park->park_code}_greater_1440_big"]??0)->cells($this->safeChr($start) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['greater_1440_big'] += $value["time_{$park->park_code}_greater_1440_big"]??0;

                    $sheet->setCellValue($this->safeChr($start + 1) . $index, $value["time_{$park->park_code}_greater_1440_little"]??0)->cells($this->safeChr($start + 1) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['greater_1440_little'] += $value["time_{$park->park_code}_greater_1440_little"]??0;

                    $index++;

                    $sheet->setCellValue($this->safeChr($start) . $index, $value["time_{$park->park_code}_big"]??0)->cells($this->safeChr($start) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['big'] += $value["time_{$park->park_code}_big"]??0;

                    $sheet->setCellValue($this->safeChr($start + 1) . $index, $value["time_{$park->park_code}_little"]??0)->cells($this->safeChr($start + 1) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['little'] += $value["time_{$park->park_code}_little"]??0;
                    $index++;

                    $sheet->setCellValue($this->safeChr($start) . $index, $value["time_{$park->park_code}_total"]??0)->cells($this->safeChr($start) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $total['total'] += $value["time_{$park->park_code}_total"]??0;

                    $sheet->mergeCells($this->safeChr($start) . $index . ':' . $this->safeChr($start + 1) . $index, 'center');

                    $start += 2;
                }

                $sheet->setCellValue($this->safeChr($start) . '2', '小计')->cells($this->safeChr($start) . '2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->mergeCells($this->safeChr($start) . '2:' . $this->safeChr($start + 1) . '2','center');
                $sheet->setCellValue($this->safeChr($start) . '3', '大车')->cells($this->safeChr($start) . '3', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue($this->safeChr($start + 1) . '3', '小车')->cells($this->safeChr($start) . '3', function ($cell){
                    $cell->setAlignment("center");
                });
                //设置单元格
                $sheet->setCellValue($this->safeChr($start) . '4', $total["0_15_big"])->cells($this->safeChr($start) . '4', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue($this->safeChr($start + 1) . '4', $total["0_15_little"])->cells($this->safeChr($start + 1) . '4', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue($this->safeChr($start) . '5', $total["15_30_big"])->cells($this->safeChr($start) . '5', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue($this->safeChr($start + 1) . '5', $total["15_30_little"])->cells($this->safeChr($start + 1) . '5', function ($cell){
                    $cell->setAlignment("center");
                });


                $index = 6;
                for ($i = 30; $i < 1440; $i += 30) {
                    $end = $i + 30;
                    $sheet->setCellValue($this->safeChr($start) . $index, $total["{$i}_{$end}_big"])->cells($this->safeChr($start) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue($this->safeChr($start + 1) . $index, $total["{$i}_{$end}_little"])->cells($this->safeChr($start + 1) . $index, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $index++;
                }
                $sheet->setCellValue($this->safeChr($start) . $index, $total["greater_1440_big"])->cells($this->safeChr($start) . $index, function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue($this->safeChr($start + 1) . $index, $total["greater_1440_little"])->cells($this->safeChr($start + 1) . $index, function ($cell){
                    $cell->setAlignment("center");
                });

                $index++;
                $sheet->setCellValue($this->safeChr($start) . $index, $total["big"])->cells($this->safeChr($start) . $index, function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue($this->safeChr($start + 1) . $index, $total['little'])->cells($this->safeChr($start + 1) . $index, function ($cell){
                    $cell->setAlignment("center");
                });

                $index++;

                $sheet->setCellValue($this->safeChr($start) . $index, $total["total"])->cells($this->safeChr($start) . $index, function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->mergeCells($this->safeChr($start) . $index . ':' . $this->safeChr($start + 1) . $index,'center');

            });
        })->export('xls');
    }

    /**
     * asiic码转字符串
     *
     * @param $code
     * @return string
     */
    private function safeChr($code)
    {
        if ($code <= 90) {
            return chr($code);
        } else {
            return 'A' . chr($code - 26);
        }
    }

    public function charge_count_month_report($value)
    {
        $this->charge_count_day_report($value);
    }

    public function charge_count_year_report($value)
    {
        $this->charge_count_day_report($value);
    }

    public function index(Request $request)
    {
        $type = $request->get('type');
        $start_day = $request->get('start_day','');
        $end_day = $request->get('end_day','');

        $reports = Report::where('type', 'like', '%' . $type . '%');
        if(isset($start_day) && !empty($start_day)){
            $reports = $reports->where("report_date",">=",$start_day);
        }
        if(isset($end_day) && !empty($end_day)){
            $reports = $reports->where("report_date","<=",$end_day);
        }
        $reports = $reports->orderBy('report_date','desc')->paginate($request->limit);

        return $this->sendResponse($reports->toArray(), '请求成功');
    }

    public function income_count_day_report($value){
        $parks = ParkInfo::whereIn('park_code', config('custom.report_parks'))
            ->select(['park_code', 'parking_name'])
            ->orderBy('sort_by', 'desc')
            ->get();
        $parks_code = config('custom.report_parks');
        $sort_num = 0;
        foreach ($parks_code as $val) {
            foreach ($parks as &$p) {
                if($p->park_code == $val){
                    $p->sort_num = $sort_num;
                    $sort_num++;
                }
            }
        }
        $parks = $parks->sortBy('sort_num');
        $day_type = count(explode("-",$_GET['report_date']));
        $title = $day_type==2? "月" : "日";
        Excel::create("收入".$title."报表", function ($excel) use ($value, $parks,$title) {
            $excel->sheet('sheet1', function ($sheet) use ($value, $parks,$title) {
                $date = date("Y年m月d号",strtotime($_GET['report_date']));
                $sheet->setCellValue('A1', '商业管理部停车场支付方式'.$title.'报表('.$_GET['report_date'].')     ');
                $sheet->setWidth(array('A' => 35));
                $sheet->mergeCells('A1:O1','center');
                $sheet->setCellValue('A2', '车场名称');
                $sheet->mergeCells('A2:A3','center');

                $sheet->setCellValue('B2', '现金');
                $sheet->mergeCells('B2:C2','center');
                $sheet->setCellValue('B3', '笔数')->cells('B3', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('C3', '收入')->cells('C3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('D2', 'etc');
                $sheet->mergeCells('D2:E2','center');
                $sheet->setCellValue('D3', '笔数')->cells('D3', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('E3', '收入')->cells('E3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('F2', '微信');
                $sheet->mergeCells('F2:G2','center');
                $sheet->setCellValue('F3', '笔数')->cells('F3', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('G3', '收入')->cells('G3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('H2', '支付宝');
                $sheet->mergeCells('H2:I2','center');
                $sheet->setCellValue('H3', '笔数')->cells('H3', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('I3', '收入')->cells('I3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('J2', 'POS');
                $sheet->mergeCells('J2:K2','center');
                $sheet->setCellValue('J3', '笔数')->cells('J3', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('K3', '收入')->cells('K3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('L2', '其他');
                $sheet->mergeCells('L2:M2','center');
                $sheet->setCellValue('L3', '笔数')->cells('L3', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('M3', '收入')->cells('M3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('N2', '线上小计');
                $sheet->mergeCells('N2:O2','center');
                $sheet->setCellValue('N3', '笔数')->cells('N3', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('O3', '收入')->cells('O3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('P2', '合计');
                $sheet->mergeCells('P2:Q2','center');
                $sheet->setCellValue('P3', '笔数')->cells('P3', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('Q3', '收入')->cells('Q3', function ($cell){
                    $cell->setAlignment("center");
                });
                $etc_num = 0;
                $etc_money = 0;
                $wei_num = 0;
                $wei_money = 0;
                $ali_num = 0;
                $ali_money = 0;
                $pos_num = 0;
                $pos_money = 0;
                $cash_num = 0;
                $cash_money = 0;
                $other_num = 0;
                $other_money = 0;
                $small_num = 0;
                $small_money = 0;
                $all_num = 0;
                $all_money = 0;
                $i = 4;
                foreach ($parks as $v) {
                    $number = 0;
                    $money = 0;
                    $anumber = 0;
                    $amoney = 0;
                    $sheet->setCellValue('A' . $i, $v->parking_name.'    ')->cells('A' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });


                    //cash
                    $type = ['pay_amount' => 0, 'pay_number' => 0];
                    if (isset($value["number_1_{$v->park_code}"])) {
                        $type['pay_number'] = $value["number_1_{$v->park_code}"];
                        $type['pay_amount'] = $value["charge_1_{$v->park_code}"];
                        $number += $type['pay_number'];
                        $money += $type['pay_amount'];
                        $cash_num += $type['pay_number'];
                        $cash_money += $type['pay_amount'];
                    }
                    // 现金

                    $sheet->setCellValue('B' . $i, $type['pay_number'].' ')->cells('B' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('C' . $i, $type['pay_amount'].' ')->cells('C' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });

                    //etc
                    $type = ['pay_amount' => 0, 'pay_number' => 0];
                    if (isset($value["number_5_{$v->park_code}"])) {
                        $type['pay_number'] = $value["number_5_{$v->park_code}"];
                        $type['pay_amount'] = $value["charge_5_{$v->park_code}"];
                        $number += $type['pay_number'];
                        $money += $type['pay_amount'];
                        $anumber += $type['pay_number'];
                        $amoney += $type['pay_amount'];
                        $etc_num += $type['pay_number'];
                        $etc_money += $type['pay_amount'];
                    }

                    $sheet->setCellValue('D' . $i, $type['pay_number'].' ')->cells('D' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('E' . $i, $type['pay_amount'].' ')->cells('E' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });

                    //wechat
                    $type = ['pay_amount' => 0, 'pay_number' => 0];
                    if (isset($value["number_2_{$v->park_code}"])) {
                        $type['pay_number'] = $value["number_2_{$v->park_code}"];
                        $type['pay_amount'] = $value["charge_2_{$v->park_code}"];
                        $number += $type['pay_number'];
                        $money += $type['pay_amount'];
                        $anumber += $type['pay_number'];
                        $amoney += $type['pay_amount'];
                        $wei_num += $type['pay_number'];
                        $wei_money += $type['pay_amount'];
                    }

                    $sheet->setCellValue('F' . $i, $type['pay_number'].' ')->cells('F' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('G' . $i, $type['pay_amount'].' ')->cells('G' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });

                    //alipay
                    $type = ['pay_amount' => 0, 'pay_number' => 0];
                    if (isset($value["number_3_{$v->park_code}"])) {
                        $type['pay_number'] = $value["number_3_{$v->park_code}"];
                        $type['pay_amount'] = $value["charge_3_{$v->park_code}"];
                        $number += $type['pay_number'];
                        $money += $type['pay_amount'];
                        $anumber += $type['pay_number'];
                        $amoney += $type['pay_amount'];
                        $ali_num += $type['pay_number'];
                        $ali_money += $type['pay_amount'];
                    }

                    $sheet->setCellValue('H' . $i, $type['pay_number'].' ')->cells('H' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('I' . $i, $type['pay_amount'].' ')->cells('I' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });

                    //pos
                    $type = ['pay_amount' => 0, 'pay_number' => 0];
                    if (isset($value["number_4_{$v->park_code}"])) {
                        $type['pay_number'] = $value["number_4_{$v->park_code}"];
                        $type['pay_amount'] = $value["charge_4_{$v->park_code}"];
                        $number += $type['pay_number'];
                        $money += $type['pay_amount'];
                        $anumber += $type['pay_number'];
                        $amoney += $type['pay_amount'];
                        $pos_num += $type['pay_number'];
                        $pos_money += $type['pay_amount'];
                    }

                    $sheet->setCellValue('J' . $i, $type['pay_number'].' ')->cells('J' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('K' . $i, $type['pay_amount'].' ')->cells('K' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });

                    //other
                    $type = ['pay_amount' => 0, 'pay_number' => 0];
                    if (isset($value["number_0_{$v->park_code}"])) {
                        $type['pay_number'] = $value["number_0_{$v->park_code}"];
                        $type['pay_amount'] = $value["charge_0_{$v->park_code}"];
                        $number += $type['pay_number'];
                        $money += $type['pay_amount'];
                        $other_num += $type['pay_number'];
                        $other_money += $type['pay_amount'];
                    }
                    $small_num += $anumber;
                    $small_money += $amoney;
                    $all_num += $number;
                    $all_money += $money;
                    // 其他
                    $sheet->setCellValue('L' . $i, $type['pay_number'].' ')->cells('L' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('M' . $i, $type['pay_amount'].' ')->cells('M' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });

                    //小计
                    $sheet->setCellValue('N' . $i, '' . $anumber.' ')->cells('N' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('O' . $i, '' . (re2float($amoney)).' ')->cells('O' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    //合计
                    $sheet->setCellValue('P' . $i, '' . $number.' ')->cells('P' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('Q' . $i, '' . $money.' ')->cells('Q' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $i++;
                }
                $sheet->setCellValue('A'.$i, '总计');
                $sheet->mergeCells('A'.$i.':A'.$i,'center');
                //现金
                $sheet->setCellValue('B'.$i, $cash_num)->cells('B'.$i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('C'.$i, $cash_money)->cells('C'.$i, function ($cell){
                    $cell->setAlignment("center");
                });

                // etc
                $sheet->setCellValue('D'.$i, $etc_num)->cells('D'.$i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('E'.$i, $etc_money)->cells('E'.$i, function ($cell){
                    $cell->setAlignment("center");
                });
                //微信
                $sheet->setCellValue('F'.$i, $wei_num)->cells('F'.$i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('G'.$i, $wei_money)->cells('G'.$i, function ($cell){
                    $cell->setAlignment("center");
                });
                //支付宝
                $sheet->setCellValue('H'.$i, $ali_num)->cells('H'.$i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('I'.$i, $ali_money)->cells('I'.$i, function ($cell){
                    $cell->setAlignment("center");
                });
                //POS
                $sheet->setCellValue('J'.$i, $pos_num)->cells('J'.$i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('K'.$i, $pos_money)->cells('K'.$i, function ($cell){
                    $cell->setAlignment("center");
                });

                //其他
                $sheet->setCellValue('L'.$i, $other_num)->cells('L'.$i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('M'.$i, $other_money)->cells('M'.$i, function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('N'.$i, $small_num)->cells('N'.$i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('O'.$i, $small_money)->cells('O'.$i, function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('P'.$i, $all_num)->cells('P'.$i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('Q'.$i, $all_money)->cells('Q'.$i, function ($cell){
                    $cell->setAlignment("center");
                });
            });
        })->export('xls');
    }

    public function income_per_month_report($value)
    {
        $this->income_count_day_report($value);
    }
    public function income_count_month_report($value)
    {
        $this->income_count_day_report($value);
    }

    public function income_count_year_report($value)
    {
        $this->income_count_day_report($value);
    }

    public function out_count_day_report($value)
    {
        $parks = ParkInfo::whereIn('park_code', config('custom.report_parks'))
            ->select(['park_code', 'parking_name'])
            ->orderBy('sort_by', 'desc')
            ->pluck('parking_name', 'park_code')->toArray();
//        $parks_code = config('custom.report_parks');
//        $sort_num = 0;
//        $npark = [];
//        foreach ($parks_code as $val) {
//            if(isset($parks[$val])){
//                $npark[$val] = $parks[$val];
//            }
//        }
//        $parks = $npark;
        $cellData = [
            ['出车通道     ', '车流量     ', '小计     ']
        ];

        Excel::create('出入口流量', function ($excel) use ($value, $parks, $cellData) {
            $excel->sheet('sheet1', function ($sheet) use ($value, $parks, $cellData) {
                $date = date("Y年m月",strtotime($_GET['report_date']));
                $sheet->setCellValue('A1', '出口流量月报表('.$date.')     ');
                $sheet->mergeCells('A1:C1','center');

                $sheet->setCellValue('A2' , $cellData[0][0])->cells('A2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('B2' , $cellData[0][1])->cells('B2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('C2' , $cellData[0][2])->cells('C2', function ($cell){
                    $cell->setAlignment("center");
                });

                $i = 3;
                $total=0;
                foreach ($value as $v) {
                    $num = count($v);
                    if ($num < 1) continue;
                    //$sheet->setCellValue('A'.$i,$parks[$v[0]['park_code']]);
                    //$sheet->mergeCells('D'.$i.':'.'A'.($i+$num-1));

                    $sheet->mergeCells('C' . $i . ':' . 'C' . ($i + $num - 1));
                    $little_total = collect($v)->sum('flow');
                    foreach ($v as $row) {
                        //查询出口名字
                        $out = ParkChannels::where([
                            'park_code'=>$row['park_code'],
                            'arm_code'=>$row['out_arm_code'],
                            'type'=>140,
                            ])->first();
                       $name='';
                       if($out){
                           $name=$out->name;
                       }
                        $sheet->setCellValue('A' . $i, ($parks[$row['park_code']]??'').' '.$name);
                        $sheet->setCellValue('B' . $i, $row['flow']);
                        $sheet->setCellValue('C' . $i, $little_total);
                        $i++;
                    }

                    $total += $little_total;
                }

                $sheet->setCellValue('A' . $i, '合计')->cells('A' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('B' . $i, $total)->cells('B' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('C' . $i, $total)->cells('C' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
            });
        })->export('xls');
    }


    public function pbus_taxi_day_report($value)
    {
        $cellDataTitle = [
            ['Pbus', '蓄车池', 'P23', '合计']
        ];
        $cellData = [
            ['日期', '流量', '收入', '流量', '收入','流量', '收入', '流量', '收入']
        ];

        Excel::create('出租车月报表', function ($excel) use ($value, $cellData, $cellDataTitle) {
            $excel->sheet('sheet1', function ($sheet) use ($value, $cellData, $cellDataTitle) {
                $date = date("Y年m月d号",strtotime($_GET['report_date']));
                $sheet->setCellValue('A1', '出租车日报表('.$date.')     ');
                $sheet->mergeCells('A1:J1','center');

                $sheet->setCellValue('B2' , $cellDataTitle[0][0])->cells('B2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->mergeCells('B2:C2','center');
                $sheet->setCellValue('D2' , $cellDataTitle[0][1])->cells('D2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->mergeCells('D2:E2','center');
                $sheet->setCellValue('F2' , $cellDataTitle[0][2])->cells('F2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->mergeCells('F2:G2','center');

                $sheet->setCellValue('H2' , $cellDataTitle[0][3])->cells('H2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->mergeCells('H2:I2','center');

                //
                $sheet->setCellValue('A3' , $cellData[0][0])->cells('A3', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('B3' , $cellData[0][1])->cells('B3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('C3' , $cellData[0][2])->cells('C3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('D3' , $cellData[0][3])->cells('D3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('E3' , $cellData[0][4])->cells('E3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('F3' , $cellData[0][5])->cells('F3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('G3' , $cellData[0][6])->cells('G3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('H3' , $cellData[0][7])->cells('H3', function ($cell){
                    $cell->setAlignment("center");
                });

                $sheet->setCellValue('I3' , $cellData[0][8])->cells('I3', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setWidth(array('A' => 25, 'B' => 25, 'C' => 25, 'D' => 25, 'E' => 25, 'F' => 25, 'G' => 25, 'H' => 25, 'I' => 25));
                $sheet->rows($cellData);
                $i = 4;
                $total=0;

                $num_total = collect($value)->sum('num');
                $money_total = collect($value)->sum('money');
                $num_total2 = collect($value)->sum('num2');
                $money_total2 = collect($value)->sum('money2');
                $num_total3 = collect($value)->sum('num3');
                $money_total3 = collect($value)->sum('money3');
                $tnum_total = collect($value)->sum('tnum');
                $tmoney_total = collect($value)->sum('tmoney');
                foreach ($value as $v) {
                    $num = count($v);
                    if ($num < 1) continue;
                    //$sheet->setCellValue('A'.$i,$parks[$v[0]['park_code']]);
                    //$sheet->mergeCells('D'.$i.':'.'A'.($i+$num-1));

                    $sheet->setCellValue('A' . $i, $v['time'] )->cells('A' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('B' . $i, $v['num'] )->cells('B' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('C' . $i, $v['money'] )->cells('C' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('D' . $i, $v['num2'] )->cells('D' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('E' . $i, $v['money2'] )->cells('E' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('F' . $i, $v['num3'] )->cells('F' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('G' . $i, $v['money3'] )->cells('G' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('H' . $i, $v['tnum'] )->cells('H' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('I' . $i, $v['tmoney'] )->cells('I' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $i++;
                }
                $sheet->setCellValue('A' . $i, '总计')->cells('A' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('B' . $i, $num_total)->cells('B' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('C' . $i, $money_total)->cells('C' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('D' . $i, $num_total2)->cells('D' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('E' . $i, $money_total2)->cells('E' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('F' . $i, $num_total3)->cells('F' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('G' . $i, $money_total3)->cells('G' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('H' . $i, $tnum_total)->cells('H' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('I' . $i, $tmoney_total)->cells('I' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
            });
        })->export('xls');
    }

    public function sell_count_month_report($value)
    {
        $cellData = [
            ['商户名       ', '配置类型     ', '配置时长（小时）     ', '配置金额     ', '结算周期     ', '结算时间     ', '电话     ', '地址     ', '备注     ']
        ];

        Excel::create('后付费商户统计月报表', function ($excel) use ($value, $cellData) {
            $excel->sheet('sheet1', function ($sheet) use ($value, $cellData) {
                $date = date("Y年m月",strtotime($_GET['report_date']));
                $sheet->setCellValue('A1', '后付费商户统计月报表('.$date.')     ');
                $sheet->mergeCells('A1:I1','center');

                $sheet->setCellValue('A2' , $cellData[0][0])->cells('A2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('B2' , $cellData[0][1])->cells('B2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('C2' , $cellData[0][2])->cells('C2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('D2' , $cellData[0][3])->cells('C2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('E2' , $cellData[0][4])->cells('C2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('F2' , $cellData[0][5])->cells('C2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('G2' , $cellData[0][6])->cells('C2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('H2' , $cellData[0][7])->cells('C2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('I2' , $cellData[0][8])->cells('C2', function ($cell){
                    $cell->setAlignment("center");
                });
                $i = 3;
                $total=0;

                foreach ($value as $v) {
                    $sheet->setCellValue('A' . $i, $v['store_name'] )->cells('A' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('B' . $i, $v['type_name'] )->cells('B' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('C' . $i, $v['duration'] )->cells('C' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('D' . $i, $v['money'] )->cells('D' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('E' . $i, $v['settle_period'] )->cells('E' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('F' . $i, $v['settle_time'] )->cells('F' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('G' . $i, $v['phone'] )->cells('G' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('H' . $i, $v['address'] )->cells('H' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $sheet->setCellValue('I' . $i, $v['note'] )->cells('I' . $i, function ($cell){
                        $cell->setAlignment("center");
                    });
                    $i++;
                }
            });
        })->export('xls');
    }


    public function invoice_count_month_report($value)
    {
        $cellData = [
            [
                '当月收入总额(元)       ', '当月收入中已开票额(元)     ',
                '当月收入中未开票额(元)     ', '上月收入中当月开票额(元)     '
            ]
        ];
        $date = date("Y年m月",strtotime($_GET['report_date']));

        Excel::create('停车场发票开具情况月报表('.$date.')', function ($excel) use ($value, $cellData, $date) {
            $excel->sheet('sheet1', function ($sheet) use ($value, $cellData, $date) {
                $sheet->setCellValue('A1', '停车场发票开具情况月报表('.$date.')     ');
                $sheet->mergeCells('A1:D1','center');

                $sheet->setCellValue('A2' , $cellData[0][0])->cells('A2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('B2' , $cellData[0][1])->cells('B2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('C2' , $cellData[0][2])->cells('C2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('D2' , $cellData[0][3])->cells('D2', function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setWidth(array('A' => 25,'B' => 25,'C' => 25,'D' => 35));
                $i = 3;
                $total=0;

                $sheet->setCellValue('A' . $i, $value[0]/100 )->cells('A' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('B' . $i, $value[1]/100 )->cells('B' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('C' . $i, $value[2]/100 )->cells('C' . $i, function ($cell){
                    $cell->setAlignment("center");
                });
                $sheet->setCellValue('D' . $i, $value[3]/100 )->cells('D' . $i, function ($cell){
                    $cell->setAlignment("center");
                });

            });
        })->export('xls');
    }
}
